/**
 * Created with IntelliJ IDEA
 * Description:
 * User: Administrator
 * Data: 2023 - 08 - 22
 * Time: 19:57
 */
//牛客 合并两个排序的链表
class Solution5 {
    public ListNode Merge (ListNode pHead1, ListNode pHead2) {
        ListNode node = new ListNode(-1);
        ListNode cur = node;
        while (pHead1 != null && pHead2 != null) {
            if (pHead1.val < pHead2.val) {
                cur.next = pHead1;
                cur = cur.next;
                pHead1 = pHead1.next;
            } else {
                cur.next = pHead2;
                cur = cur.next;
                pHead2 = pHead2.next;
            }
        }
        while (pHead1 != null) {
            cur.next = pHead1;
            break;
        }
        while (pHead2 != null) {
            cur.next = pHead2;
            break;
        }
        return node.next;
    }
}
